package lenovo.asd.wangdwa;

import java.io.InputStream;
import java.util.List;

import lenovo.asd.wangdwa.R;
import lenovo.asd.xml.SAXTaskService;
import lenovo.asd.xml.Task;
import lenovo.asd.xml.WifiSAXService;
import lenovo.asd.xml.WifiTask;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class DroidoActivity extends Activity {
    /** Called when the activity is first created. */
	// me: TAG for debugging
	private static final String TAG = "DroidoActivity";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // me: link the resource to para.
        TextView resultsView = (TextView)this.findViewById(R.id.results);
        // me: put config.xml in.
        InputStream inStream = DroidoActivity.class.getClassLoader().getResourceAsStream("config.xml");
        
        // me: start to work
       StringBuilder sb = new StringBuilder();
        try {
			List<Task> tasks = SAXTaskService.readXml(inStream);
//			StringBuilder sb = new StringBuilder();
			
			for (Task task : tasks) {
				sb.append(task.toString()).append("\n\n");
			}
//			resultsView.setText(sb.toString());
		} catch (Exception e) {
			// TODO: handle exception
			Toast.makeText(this, "XML parceing failed.", Toast.LENGTH_LONG).show();
		}        
		
		inStream = DroidoActivity.class.getClassLoader().getResourceAsStream("config.xml");
		try {
			List<WifiTask> wifiTasks = WifiSAXService.readXml(inStream);
//			StringBuilder sb = new StringBuilder();
			
			for (WifiTask wifiTask : wifiTasks) {
				sb.append(wifiTask.toString()).append("\n\n");
			}
//			resultsView.setText(sb.toString());
		} catch (Exception e) {
			// TODO: handle exception
			Toast.makeText(this, "XML (Wifi node) parceing failed.", Toast.LENGTH_LONG).show();
		}
        
		
		resultsView.setText(sb.toString());
    }
}